diff --git a/django/core/management/commands/__init__.py b/django/core/management/commands/__init__.py
index e69de29bb2..aefb1d5bd2 100644
--- a/django/core/management/commands/__init__.py
+++ b/django/core/management/commands/__init__.py
@@ -0,0 +1,6 @@
+
+from django.conf import settings
+
+# Set a default SECRET_KEY for the makemigrations command if not already configured
+if not hasattr(settings, 'SECRET_KEY') or not settings.SECRET_KEY:
+    settings.SECRET_KEY = 'temporary_secret_key_for_makemigrations'
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index 5c0a7829b4..a050c96353 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -1,13 +1,20 @@
+from django.conf import settings
+from django import setup
+
+if not settings.configured:
+    settings.configure(SECRET_KEY='temporary_secret_key_for_makemigrations')
+    setup()
+
 import os
 import sys
 import warnings
 from itertools import takewhile
 
 from django.apps import apps
-from django.conf import settings
 from django.core.management.base import (
     BaseCommand, CommandError, no_translations,
 )
+from django.core.management.color import color_style
 from django.db import DEFAULT_DB_ALIAS, OperationalError, connections, router
 from django.db.migrations import Migration
 from django.db.migrations.autodetector import MigrationAutodetector
@@ -70,6 +77,7 @@ class Command(BaseCommand):
             raise CommandError('The migration name must be a valid Python identifier.')
         self.include_header = options['include_header']
         check_changes = options['check_changes']
+        self.style = color_style()
 
         # Make sure the app they asked for exists
         app_labels = set(app_labels)
